package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;


public class ProductCTR
{
    private ProductContainer pctr;

    /**
     * Constructor for objects of class ProductCTR
     */
    public ProductCTR()
    {
        pctr = pctr.getInstance();
    }
     /**
     * Finds the product entry in array via its title.
     * 
     * @param productID the product title to be used in search
     */
    public Product findProduct(int id)
    {
        return pctr.findProduct(id);
    }
        /**
     * Creating a new entry in the product array
     * 
     * @param productID sets the productID for the entry
     * @param productName sets the productName for the entry
     * @param desc sets the desc for the entry
     * @param price sets the price for the entry
     * @param salePrice sets the salePrice for the entry
     * @param quantity sets the quantity for the entry
     * @param stock sets the stock for the entry
     * @param row sets the row for the entry
     * @param shelf sets the shelf for the entry
     */
    public void createProduct(int productID, String productName, String desc, double price, double salePrice, int quantity, int stock, int row, int shelf)
    {
        Product product = new Product(productID, productName, desc, price, salePrice, quantity, stock, row, shelf);
        pctr.addProduct(product); 
    }
    /**
     * Deleting a Product with the use of its productID.
     * 
     * @param the productID to be used in deleting
     */
    public boolean deleteProduct(int id)
    {
        return pctr.deleteProduct(id);
    }
    /**
     * Adding a specimen in the array.
     * 
     * @param productID sets the productID for the enty
     * @param serial sets the serial date for the entry
     */
    public Specimen getSpecimen(int productID, int serial)
    {
        return pctr.getSpecimen(productID, serial);
    }
    /**
     * Lists all products in array.
     */
    public ArrayList listAllProducts()
    {
        return null;
    }
    public void createSpeciman(int productID, int serial)
    {
        int index = 0;
        boolean found = false;
        Specimen specimen = new Specimen(serial);
        while(index < pctr.productContainer.size() && !found)
        {
            if(pctr.productContainer.get(index).getProductID() == productID)
            {
                found = true;
                pctr.productContainer.get(index).createSpecimen(specimen);
            }
            else
            {
                index++;
            }
        }
    }
    public void updateProduct(Product product, int choise, String newData, int newInt, double newDouble)
    {
        if(choise == 1)
        {
            product.setProductName(newData);
        }
        if(choise == 2)
        {
            product.setDesc(newData);
        }
        if(choise == 3)
        {
            product.setPrice(newDouble);
        }
        if(choise == 4)
        {
            product.setSalePrice(newDouble);
        }
        if(choise == 5)
        {
            product.setQuantity(newInt);
        }
        if(choise == 6)
        {
            product.setStock(newInt);
        }
        if(choise == 7)
        {
            product.setRow(newInt);
        }
        if(choise == 8)
        {
            product.setShelf(newInt);
        }
        
    }
    
    
}
